package bb.lanxing.model.database;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.litepal.LitePal;

import com.alibaba.fastjson.JSON;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.model.LatLngBounds;
import com.garmin.fit.MonitoringReader;
import com.github.mikephil.charting.utils.Utils;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import bb.lanxing.App;
import bb.lanxing.common.config.Constants;
import bb.lanxing.lib.devices.sprint.entity.SprintNav;
import bb.lanxing.manager.SharedManager;
import bb.lanxing.model.data.Notepoint;
import bb.lanxing.model.json.ServerLushu;
import bb.lanxing.model.json.TrackSegment;
import bb.lanxing.model.json.UserAvatarMedal;
import bb.lanxing.network.GoogleClient;
import bb.lanxing.test.PolylineUtil;
import bb.lanxing.util.AppFileUtils;
import bb.lanxing.util.BiCiCoorConverter;
import bb.lanxing.util.CommonUtil;
import bb.lanxing.util.JsonUtil;
import bb.lanxing.util.Log;
import bb.lanxing.util.MedalUtil;
import bb.lanxing.util.thread.ThreadPools;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class RouteBook extends LitePalTableBase implements Serializable, Parcelable, SprintNav {
    public static final String ACTION_DOWNLOAD_LUSHU = "bb.lanxing.downLushu";
    public static final String ACTION_IMAGE_LOADED = "bb.lanxing.uploadedLushuImage";
    public static final String ACTION_WORKOUT_CREATE_LUSHU = "bb.lanxing.workout.createlushu";
    public static final String ACTION_DELETE_LUSHU = "bb.lanxing.deleteLushu";

    public static final Creator<RouteBook> CREATOR = new Creator<>() {
        @Override
        public RouteBook createFromParcel(Parcel source) {
            return new RouteBook(source);
        }

        @Override
        public RouteBook[] newArray(int size) {
            return new RouteBook[size];
        }
    };
    public static final int STYLE_DEFAULT = 0;
    public static final int STYLE_TOUR_DE_FRANCE = 1;
    public static final int TYPE_UNKNOWN = -1;
    public static final int TYPE_GOOGLE = 0;
    public static final int TYPE_IMPORT = 1;
    public static final int TYPE_DRAW = 2;
    public static final int TYPE_BAIDU = 3;
    public static final int TYPE_HUAWEI = 4;
    public static final int TYPE_SOURCE_CREATE = 1;
    public static final int TYPE_SOURCE_WORKOUT = 2;

    private static final String TAG = "Lushu";
    private static final String COLUMNS_ALL =
            "id, distance, title, importtime, imported, filename, uuid, serverid, startaddress, endaddress, userid, imageurl, description, servertype, username, useravatar, commentcount, downloadcount, iscollected,collectcount, sport, sourcetype, createtime, isupload, threedlushu, similaritynum, isdisplay, encodingpoints, waypointstring, notepointstring, altitudestring, updatetime, needupdate,level,medalsmall,platenum,isdownload,uploadenable,catdflevel, style, thumbnail,slopethumbnail,elevationgain,avggrade";
    private static final String COLUMNS_LIST =
            "id, distance, title, filename, uuid, serverid, userid, imageurl, servertype, useravatar, commentcount, downloadcount, sport, sourcetype, createtime, isupload, threedlushu, similaritynum, isdisplay, updatetime, needupdate, isdownload, uploadenable, catdflevel, style, thumbnail,slopethumbnail,elevationgain,avggrade";
    private static SQLiteDatabase db;
    List<UserAvatarMedal> userAvatarMedals;
    private String altitudeString;
    private double avgGrade;
    private int caTdfLevel;
    private int collectCount;
    private int commentCount;
    private String copyrights;
    private long createTime;
    private String description;
    private double distance;
    private int downloadCount;
    private double elevationGain;
    private double elevationLoss;
    private String encodingPoints;
    private String endAddress;
    private String fileName;
    private String imageUrl;
    private long importTime;
    private boolean imported;
    private boolean isCollected;
    private boolean isDisplay;
    private boolean isDownload;
    private boolean isExport;
    private boolean isUpload;
    private int level;
    private String licenseNumberColor;
    private String licenseNumberSkin;
    private List<RouteBookPoint> lushuPoints;
    private double maxAltitude;
    private double maxGrade;
    private String medalSmall;
    private double minAltitude;
    private double minGrade;
    private boolean needUpdate;
    private double northeastLat;
    private double northeastLng;
    private String notepointString;
    private String plateNum;
    private String proName;
    private long serverId;
    private int serverType;
    private int similarityNum;
    private String slopeThumbnail = "";
    private int sourceType;
    private double southwestLat;
    private double southwestLng;
    private int sport;
    private String startAddress;
    private int style;
    private String threedLushu;
    private String thumbnail;
    private String title;
    private TrackSegment trackSegment;
    private long updateTime;
    private boolean uploadEnable;
    private String userAvatar;
    private long userId;
    private String username;
    private String uuid;

    private List<Waypoint> wayPoints;
    private String waypointString;

    public RouteBook() {
        this.sourceType = -1;
        this.uploadEnable = true;
        this.caTdfLevel = 0;
        this.isUpload = true;
    }

    protected RouteBook(Parcel in2) {
        this.sourceType = -1;
        this.uploadEnable = true;
        this.caTdfLevel = 0;
        this.distance = in2.readDouble();
        this.title = in2.readString();
        this.importTime = in2.readLong();
        this.imported = in2.readByte() != 0;
        this.fileName = in2.readString();
        this.uuid = in2.readString();
        this.serverId = in2.readLong();
        this.startAddress = in2.readString();
        this.endAddress = in2.readString();
        this.userId = in2.readLong();
        this.imageUrl = in2.readString();
        this.description = in2.readString();
        this.serverType = in2.readInt();
        this.username = in2.readString();
        this.userAvatar = in2.readString();
        this.level = in2.readInt();
        this.medalSmall = in2.readString();
        this.plateNum = in2.readString();
        this.proName = in2.readString();
        this.userAvatarMedals = in2.createTypedArrayList(UserAvatarMedal.CREATOR);
        this.commentCount = in2.readInt();
        this.downloadCount = in2.readInt();
        this.isCollected = in2.readByte() != 0;
        this.collectCount = in2.readInt();
        this.sport = in2.readInt();
        this.sourceType = in2.readInt();
        this.createTime = in2.readLong();
        this.isUpload = in2.readByte() != 0;
        this.threedLushu = in2.readString();
        this.similarityNum = in2.readInt();
        this.isDownload = in2.readByte() != 0;
        this.isExport = in2.readByte() != 0;
        this.trackSegment = in2.readParcelable(TrackSegment.class.getClassLoader());
        this.waypointString = in2.readString();
        this.notepointString = in2.readString();
        this.altitudeString = in2.readString();
        this.northeastLat = in2.readDouble();
        this.northeastLng = in2.readDouble();
        this.southwestLat = in2.readDouble();
        this.southwestLng = in2.readDouble();
        this.copyrights = in2.readString();
        this.isDisplay = in2.readByte() != 0;
        this.encodingPoints = in2.readString();
        this.updateTime = in2.readLong();
        this.needUpdate = in2.readByte() != 0;
        this.minGrade = in2.readDouble();
        this.maxGrade = in2.readDouble();
        this.avgGrade = in2.readDouble();
        this.minAltitude = in2.readDouble();
        this.maxAltitude = in2.readDouble();
        this.elevationGain = in2.readDouble();
        this.elevationLoss = in2.readDouble();
        this.uploadEnable = in2.readByte() != 0;
        this.lushuPoints = in2.createTypedArrayList(RouteBookPoint.CREATOR);
        this.wayPoints = in2.createTypedArrayList(Waypoint.CREATOR);
        this.caTdfLevel = in2.readInt();
        this.style = in2.readInt();
        this.thumbnail = in2.readString();
        this.slopeThumbnail = in2.readString();
        this.licenseNumberColor = in2.readString();
        this.licenseNumberSkin = in2.readString();
    }

    public static List<RouteBook> getList() {
        return listAll(RouteBook.class);
    }

    public static List<RouteBook> getAll() {
        return listAll(RouteBook.class);
    }

    public static RouteBook parseLushuByServer(JSONObject node, boolean needUpdate) {
        RouteBook routeBook;
        JSONArray arrayValue;
        Log.d(TAG, "parseLushuByServer: node = " + node);
        long serverId = JsonUtil.getLongValue("serverId", node);
        if (node.has("searchType")) {
            routeBook = getByServerIdAndServerType(serverId, JsonUtil.getIntegerValue("searchType", node));
        } else {
            routeBook = getByServerId(serverId);
        }
        if (routeBook == null) {
            routeBook = new RouteBook();
            routeBook.serverId = serverId;
        }
        if (node.has("uuid")) {
            routeBook.uuid = JsonUtil.getStringValue("uuid", node);
        }
        if (node.has("isUpload")) {
            routeBook.isUpload = JsonUtil.getIntegerValue("isUpload", node) == 1;
        }
        if (node.has("iscollected")) {
            routeBook.isCollected = JsonUtil.getIntegerValue("iscollected", node) == 1;
        }
        if (node.has("needUpdate")) {
            routeBook.needUpdate = JsonUtil.getIntegerValue("needUpdate", node) == 1;
        }
        if (node.has("userId")) {
            routeBook.userId = JsonUtil.getLongValue("userId", node);
        }
        if (node.has("username")) {
            routeBook.username = JsonUtil.getStringValue("username", node);
        }
        if (node.has("userAvatar")) {
            routeBook.userAvatar = JsonUtil.getStringValue("userAvatar", node);
        }
        if (node.has("level")) {
            routeBook.level = JsonUtil.getIntegerValue("level", node);
        }
        if (node.has("proName")) {
            routeBook.proName = JsonUtil.getStringValue("proName", node);
        }
        if (node.has("plateNum")) {
            routeBook.plateNum = JsonUtil.getStringValue("plateNumber", node);
        }
        if (node.has("medalSmall") && (!TextUtils.isEmpty(JsonUtil.getStringValue("medalSmall", node)))
                && (arrayValue = JsonUtil.getArrayValue("medalSmall", node)) != null) {
            List<UserAvatarMedal> userAvatorMedalInfo = MedalUtil.getUserAvatorMedalInfo(arrayValue);
            if (userAvatorMedalInfo != null) {
                String str = "";
                for (int i = 0; i < userAvatorMedalInfo.size(); i++) {
                    str = i == userAvatorMedalInfo.size() - 1 ? str + userAvatorMedalInfo.get(i).getUrl()
                            : str + userAvatorMedalInfo.get(i).getUrl() + ";";
                }
                routeBook.setMedalSmall(str);
            } else {
                routeBook.setMedalSmall(null);
            }
            routeBook.setUserAvatarMedals(userAvatorMedalInfo);
        }
        if (node.has("title")) {
            routeBook.title = JsonUtil.getStringValue("title", node);
        }
        if (node.has("description")) {// SocialConstants.PARAM_APP_DESC
            routeBook.description = JsonUtil.getStringValue("description", node);
        }
        if (node.has("distance")) {// MonitoringReader.DISTANCE_STRING
            routeBook.distance = JsonUtil.getDoubleValue("distance", node);
        }
        if (node.has("imageUrl")) {// SocializeProtocolConstants.IMAGE
            routeBook.imageUrl = JsonUtil.getStringValue("imageUrl", node);
        }
        if (node.has("sourceType")) {
            routeBook.sourceType = JsonUtil.getIntegerValue("sourceType", node);
        }
        if (node.has("sport")) {// SettingSupports.SUPPORT_ITEM_SPORT
            routeBook.sport = JsonUtil.getIntegerValue("sport", node);
        }
        if (node.has("commentCount")) {
            routeBook.commentCount = JsonUtil.getIntegerValue("commentCount", node);
        }
        if (node.has("downloadCount")) {
            routeBook.downloadCount = JsonUtil.getIntegerValue("downloadCount", node);
        }
        if (node.has("isCollected")) {
            routeBook.isCollected = JsonUtil.getBooleanValue("isCollected", node);
        }
        if (node.has("collectCount")) {
            routeBook.collectCount = JsonUtil.getIntegerValue("collectCount", node);
        }
        if (node.has("importTime")) {
            routeBook.createTime = JsonUtil.getLongValue("importTime", node);
        }
        if (node.has("threedLushu")) {
            routeBook.threedLushu = JsonUtil.getStringValue("threedLushu", node);
        }
        if (node.has("updateTime")) {
            long updateTime = routeBook.getUpdateTime();
            long longValue2 = JsonUtil.getLongValue("updateTime", node);
            routeBook.setUpdateTime(longValue2);
            Long id = routeBook.getId();
            if (!routeBook.isNeedUpdate() && id != null) {
                routeBook.setNeedUpdate(longValue2 > updateTime);
            }
        }
        if (node.has("isDownload")) {
            routeBook.isDownload = JsonUtil.getIntegerValue("isDownload", node) == 1;
        }
        if (node.has("isExport")) {
            routeBook.isExport = JsonUtil.getIntegerValue("isExport", node) == 1;
        }

        if (!node.isNull("wayPoints")) {
            JSONArray jsonArrayWayPoints = JsonUtil.getArrayValue("wayPoints", node);
            if (jsonArrayWayPoints != null) {
                routeBook.waypointString = jsonArrayWayPoints.toString();
            }
        }

        if (!node.isNull("lushuPoints")) {
            JSONArray jsonArrayLushuPoints = JsonUtil.getArrayValue("lushuPoints", node);
        }

        if (node.has("serverType")) {
            routeBook.serverType = JsonUtil.getIntegerValue("serverType", node);
        } else {
            routeBook.serverType = 1;
        }
        if (node.has("similarityNum")) {
            routeBook.similarityNum = JsonUtil.getIntegerValue("similarityNum", node);
        }
        if (node.has("trackSegment")) {
            routeBook.trackSegment =
                    JSON.parseObject(JsonUtil.getStringValue("trackSegment", node), TrackSegment.class);
        }
        if (node.has("minAltitude")) {
            routeBook.minAltitude = JsonUtil.getDoubleValue("minAltitude", node);
        }
        if (node.has("maxAltitude")) {
            routeBook.maxAltitude = JsonUtil.getDoubleValue("maxAltitude", node);
        }
        if (node.has("minGrade")) {
            routeBook.minGrade = JsonUtil.getDoubleValue("min_grade", node);
        }
        if (node.has("max_grade")) {
            routeBook.maxGrade = JsonUtil.getDoubleValue("minGrade", node);
        }
        if (node.has("avgGrade")) {
            routeBook.avgGrade = JsonUtil.getDoubleValue("avgGrade", node);
        }
        if (node.has("elevationGain")) {
            routeBook.elevationGain = JsonUtil.getDoubleValue("elevationGain", node);
        }
        if (node.has("elevationLoss")) {
            routeBook.elevationLoss = JsonUtil.getDoubleValue("elevationLoss", node);
        }
        if (node.has("caTdfLevel")) {
            routeBook.caTdfLevel = JsonUtil.getIntegerValue("caTdfLevel", node);
        }
        if (node.has("thumbnail")) {
            routeBook.thumbnail = JsonUtil.getStringValue("thumbnail", node);
        }
        if (node.has("slopeThumbnail")) {
            routeBook.slopeThumbnail = JsonUtil.getStringValue("slopeThumbnail", node);
        }
        if (node.has("style")) {
            routeBook.style = JsonUtil.getIntegerValue("style", node);
        }
        if (node.has("license_number_skin")) {
            routeBook.licenseNumberSkin = JsonUtil.getStringValue("license_number_skin", node);
        }
        if (node.has("licenseNumberColor")) {
            routeBook.licenseNumberColor = JsonUtil.getStringValue("licenseNumberColor", node);
        }

        return routeBook;
    }

    public static RouteBook parseLushuByGoogle(JSONObject node) {
        RouteBook routeBook = new RouteBook();
        routeBook.uuid = UUID.randomUUID().toString();
        routeBook.userId = SharedManager.getInstance().getUserId();
        routeBook.serverType = 1;
        routeBook.createTime = System.currentTimeMillis();
        routeBook.sport = 3;
        //routeBook.title = LushuTitleUtil.buildLushuDefaultTitle(App.getContext(), routeBook);
        return parseLushuByGoogle(node, routeBook);
    }

    public static RouteBook parseLushuByGoogle(JSONObject node, RouteBook routeBook) {
        routeBook.imported = false;
        routeBook.sourceType = 0;
        if (node.has("bounds")) {
            JSONObject objectValue = JsonUtil.getObjectValue("bounds", node);
            if (objectValue != null && objectValue.has("northeast")) {
                JSONObject objectValue2 = JsonUtil.getObjectValue("northeast", objectValue);
                routeBook.northeastLat = JsonUtil.getDoubleValue("lat", objectValue2);
                routeBook.northeastLng = JsonUtil.getDoubleValue("lng", objectValue2);
            }
            if (objectValue != null && objectValue.has("southwest")) {
                JSONObject objectValue3 = JsonUtil.getObjectValue("southwest", objectValue);
                routeBook.southwestLat = JsonUtil.getDoubleValue("lat", objectValue3);
                routeBook.southwestLng = JsonUtil.getDoubleValue("lng", objectValue3);
            }
        }
        if (node.has("copyrights")) {
            routeBook.copyrights = JsonUtil.getStringValue("copyrights", node);
        }
        ArrayList<LatLng> arrayList = new ArrayList<>();
        JSONArray arrayValue = JsonUtil.getArrayValue("legs", node);
        double d = 0.0d;
        if (arrayValue != null) {
            for (int i = 0; i < arrayValue.length(); i++) {
                try {
                    JSONObject jSONObject = arrayValue.getJSONObject(i);
                    JSONArray arrayValue2 = JsonUtil.getArrayValue("steps", jSONObject);
                    if (arrayValue2 != null) {
                        for (int i2 = 0; i2 < arrayValue2.length(); i2++) {
                            arrayList.addAll(CommonUtil.decodePoints(
                                    arrayValue2.getJSONObject(i2).getJSONObject("polyline").getString("points")));
                        }
                        if (jSONObject.has(MonitoringReader.DISTANCE_STRING)) {
                            d += jSONObject.getJSONObject(MonitoringReader.DISTANCE_STRING).getDouble("value");
                        }
                    }
                    if (jSONObject.has("start_address") && i == 0) {
                        routeBook
                                .setStartAddress(simplifyAddress(JsonUtil.getStringValue("start_address", jSONObject)));
                    }
                    if (jSONObject.has("end_address") && i == arrayValue.length() - 1) {
                        routeBook.setEndAddress(simplifyAddress(JsonUtil.getStringValue("end_address", jSONObject)));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        if (d > Utils.DOUBLE_EPSILON) {
            routeBook.distance = d;
        }
        routeBook.save();
        ArrayList<RouteBookPoint> arrayList2 = new ArrayList<>();
        if (!arrayList.isEmpty()) {
            RouteBookPoint.deleteByRouteBookId(routeBook.getId());
            for (LatLng latLng : arrayList) {
                LatLng common2Earth = BiCiCoorConverter.common2Earth(latLng);
                RouteBookPoint lushuPoint = new RouteBookPoint();
                lushuPoint.setLushuId(routeBook.getId());
                lushuPoint.setLatlng(common2Earth);
                arrayList2.add(lushuPoint);
            }
        }
        RouteBookPoint.savePoints(arrayList2);
        return routeBook;
    }

    private static String simplifyAddress(String address) {
        if (TextUtils.isEmpty(address)) {
            return "";
        }
        int indexOf = address.indexOf("邮政编码");
        if (indexOf > 0) {
            address = address.substring(0, indexOf);
        }
        return address.replaceAll("中国", "").trim();
    }

    public static RouteBook parseLushu(JSONObject route, RouteBook routeBook) {
        routeBook.imported = false;
        routeBook.sourceType = RouteBook.TYPE_BAIDU;
        ArrayList<LatLng> arrayList = new ArrayList<>();
        JSONArray jsonArrayWayPoints = JsonUtil.getArrayValue("wayPoints", route);
        JSONArray jsonArrayLushuPoints = JsonUtil.getArrayValue("lushuPoints", route);
        if (jsonArrayWayPoints != null) {
            routeBook.waypointString = jsonArrayWayPoints.toString();
        }
        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        LatLngBounds build = builder.build();

        routeBook.northeastLat = build.northeast.latitude;
        routeBook.northeastLng = build.northeast.longitude;
        routeBook.southwestLat = build.southwest.latitude;
        routeBook.southwestLng = build.southwest.longitude;
        routeBook.save();

        long lushuId = routeBook.getId();
        if (jsonArrayWayPoints != null && jsonArrayWayPoints.length() > 0) {
            ArrayList<Waypoint> waypointArrayList = new ArrayList<>();
            int len = jsonArrayWayPoints.length();
            for (int i2 = 0; i2 < len; i2++) {
                try {
                    Waypoint waypoint = new Waypoint(jsonArrayWayPoints.getJSONObject(i2));
                    waypoint.setLushuId(lushuId);
                    waypointArrayList.add(waypoint);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            Waypoint.savePoints(waypointArrayList);
        }

        if (null != jsonArrayLushuPoints && jsonArrayLushuPoints.length() > 0) {
            RouteBookPoint.deleteByRouteBookId(lushuId);
            ArrayList<RouteBookPoint> lushuPointArrayList = new ArrayList<>();
            int len = jsonArrayLushuPoints.length();
            for (int i2 = 0; i2 < len; i2++) {
                try {
                    JSONObject jsonObject = jsonArrayLushuPoints.getJSONObject(i2);
                    double altitude = jsonObject.getDouble("altitude");
                    double distance = jsonObject.getDouble("distance");
                    double longitude = jsonObject.getDouble("longitude");
                    double latitude = jsonObject.getDouble("latitude");

                    RouteBookPoint lushuPoint = new RouteBookPoint();
                    lushuPoint.setAltitude(altitude);
                    lushuPoint.setDistance(distance);
                    lushuPoint.setLongitude(longitude);
                    lushuPoint.setLatitude(latitude);
                    lushuPoint.setLushuId(lushuId);
                    lushuPointArrayList.add(lushuPoint);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            RouteBookPoint.savePoints(lushuPointArrayList);
        }
        return routeBook;
    }

    public static RouteBook parseLushuByBaidu(JSONObject route, RouteBook routeBook) {
        routeBook.imported = false;
        routeBook.sourceType = RouteBook.TYPE_BAIDU;
        ArrayList<LatLng> arrayList = new ArrayList<>();
        try {
            routeBook.distance = JsonUtil.getDoubleValue(MonitoringReader.DISTANCE_STRING, route);
            JSONArray arrayValue = JsonUtil.getArrayValue("steps", route);
            if (arrayValue != null) {
                for (int i = 0; i < arrayValue.length(); i++) {
                    JSONObject jSONObject = arrayValue.getJSONObject(i).getJSONObject("stepOriginLocation");
                    LatLng latLng = new LatLng(Double.parseDouble(jSONObject.getString("lat")),
                            Double.parseDouble(jSONObject.getString("lng")));
                    JSONObject jSONObject2 = arrayValue.getJSONObject(i).getJSONObject("stepDestinationLocation");
                    LatLng latLng2 = new LatLng(Double.parseDouble(jSONObject2.getString("lat")),
                            Double.parseDouble(jSONObject2.getString("lng")));
                    List<LatLng> parseBaiduPoints =
                            CommonUtil.parseBaiduPoints(arrayValue.getJSONObject(i).getString("path"));
                    arrayList.add(latLng);
                    arrayList.addAll(parseBaiduPoints);
                    arrayList.add(latLng2);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        routeBook.save();
        ArrayList<RouteBookPoint> arrayList2 = new ArrayList<>();
        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        if (!arrayList.isEmpty()) {
            RouteBookPoint.deleteByRouteBookId(routeBook.getId());
            for (LatLng latLng : arrayList) {
                LatLng baidu2Earth = BiCiCoorConverter.baidu2Earth(latLng);
                builder.include(baidu2Earth);
                RouteBookPoint lushuPoint = new RouteBookPoint();
                lushuPoint.setLushuId(routeBook.getId());
                lushuPoint.setLatlng(baidu2Earth);
                arrayList2.add(lushuPoint);
            }
        }
        RouteBookPoint.savePoints(arrayList2);
        LatLngBounds build = builder.build();
        routeBook.northeastLat = build.northeast.latitude;
        routeBook.northeastLng = build.northeast.longitude;
        routeBook.southwestLat = build.southwest.latitude;
        routeBook.southwestLng = build.southwest.longitude;
        routeBook.save();
        return routeBook;
    }

    // public static RouteBook parseLushuByStep(List<WalkingRouteLine.WalkingStep> stepList, RouteBook routeBook) {
    // routeBook.imported = false;
    // routeBook.sourceType = 3;
    // ArrayList<RouteBookPoint> arrayList = new ArrayList<>();
    // double distance = 0;
    // LatLngBounds.Builder builder = new LatLngBounds.Builder();
    // routeBook.save();
    // for (int i = 0; i < stepList.size(); i++) {
    // RouteBookPoint.deleteByRouteBookId(routeBook.getId());
    // RouteBookPoint lushuPoint = new RouteBookPoint();
    // lushuPoint.setLushuId(routeBook.getId());
    // LatLng baidu2Earth = BiCiCoorConverter.baidu2Earth(stepList.get(i).getEntrance().getLocation());
    // // System.out.println("stepList.get(i).getEntrance().getLocation(): " +
    // // stepList.get(i).getEntrance().getLocation());
    // builder.include(baidu2Earth);
    // lushuPoint.setLatlng(baidu2Earth);
    // lushuPoint.setDistance(stepList.get(i).getDistance());
    // // System.out.println("stepList.get(i).getDistance(): " + stepList.get(i).getDistance());
    // arrayList.add(lushuPoint);
    // distance += stepList.get(i).getDistance();
    // }
    // routeBook.distance = distance;
    // RouteBookPoint.savePoints(arrayList);
    // LatLngBounds build = builder.build();
    // routeBook.northeastLat = build.northeast.latitude;
    // routeBook.northeastLng = build.northeast.longitude;
    // routeBook.southwestLat = build.southwest.latitude;
    // routeBook.southwestLng = build.southwest.longitude;
    // routeBook.save();
    // return routeBook;
    // }

    public static RouteBook getByServer(ServerLushu serverLushu) {
        String serverId = String.valueOf(serverLushu.getTrailid());
        String serverType = String.valueOf(serverLushu.getType());
        return LitePal.where("serverId=? and serverType=?", serverId, serverType).findFirst(RouteBook.class);
    }

    public static RouteBook getByServerId(long serverId0) {
        String serverId = String.valueOf(serverId0);
        return LitePal.where("serverId=?", serverId).order("createTime DESC").findFirst(RouteBook.class);
    }

    public static RouteBook getByServerIdAndServerType(long id, int type) {
        String serverId = String.valueOf(id);
        String serverType = String.valueOf(type);
        return LitePal.where("serverId=? and serverType=? and createTime=?", serverId, serverType)
                .order("createTime DESC").findFirst(RouteBook.class);
    }

    public static RouteBook builderLushu(JSONObject node, RouteBook old) throws JSONException {
        if (old == null) {
            old = new RouteBook();
            old.imported = false;
            old.createTime = System.currentTimeMillis();
            old.sourceType = 3;
            old.title = "";
            old.uuid = UUID.randomUUID().toString();
        }
        old.copyrights = node.getJSONObject("info").getJSONObject("copyright").getString("text");
        JSONObject jSONObject = node.getJSONObject("result").getJSONArray("routes").getJSONObject(0);
        old.distance += jSONObject.getDouble(MonitoringReader.DISTANCE_STRING);
        JSONArray jSONArray = jSONObject.getJSONArray("steps");
        long save = old.save_();
        for (int i = 0; i < jSONArray.length(); i++) {
            parsePoint(jSONArray.getJSONObject(i).getString("path").split(";"), save);
        }
        return old;
    }

    private static void parsePoint(String[] paths, long lushuId) {
        ArrayList<RouteBookPoint> arrayList = new ArrayList<>();
        for (String str : paths) {
            String[] split = str.split(",");
            RouteBookPoint lushuPoint = new RouteBookPoint();
            lushuPoint.setLatlng(BiCiCoorConverter.common2Earth(BiCiCoorConverter
                    .baidu2Common(new LatLng(Double.parseDouble(split[1]), Double.parseDouble(split[0])))));
            lushuPoint.setLushuId(lushuId);
            arrayList.add(lushuPoint);
        }
        RouteBookPoint.savePoints(arrayList);
    }

    public static RouteBook getById(long j) {
        return LitePal.where("id=?", String.valueOf(j)).findFirst(RouteBook.class);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public boolean updateOldVersion(int sourceType, boolean isUpload) {
        if (this.id == null) {
            return false;
        }
        db = LitePal.getDatabase();
        String[] strArr = { String.valueOf(this.id) };
        ContentValues contentValues = new ContentValues();
        contentValues.put("sourcetype", sourceType);
        contentValues.put("isupload", isUpload);
        return db.update(RouteBook.class.getSimpleName(), contentValues, "id=?", strArr) > 0;
    }

    private boolean buildEncodingPoints() {
        if (this.id == null) {
            return false;
        }
        if (TextUtils.isEmpty(this.encodingPoints)) {
            this.encodingPoints = PolylineUtil.encode(RouteBookPoint.getLatLngForGoogleStaticMap(this.id));
            save();
            return !TextUtils.isEmpty(this.encodingPoints);
        }
        return true;
    }

    public void uplaodLoadImage() {
        if (buildEncodingPoints()) {
            ThreadPools.getInstance().addTask(new Runnable() {
                @Override
                public void run() {
                    RouteBook.this.downloadLushuImage();
                }
            });
        }
    }

    public void downloadLushuImage() {
        ArrayList<LatLng> arrayList = new ArrayList<>();
        if (this.id != null) {
            List<Waypoint> byLushuId = Waypoint.getByLushuId(this.id);
            if (byLushuId != null && !byLushuId.isEmpty()) {
                for (Waypoint waypoint : byLushuId) {
                    arrayList.add(BiCiCoorConverter.earth2Common(waypoint.getLatLng()));
                }
            } else {
                List<RouteBookPoint> byLushuId2 = RouteBookPoint.getByLushuId(this.id);
                if (byLushuId2 != null && !byLushuId2.isEmpty()) {
                    arrayList.add(BiCiCoorConverter.earth2Common(byLushuId2.get(0).getLatLng()));
                    arrayList.add(BiCiCoorConverter.earth2Common(byLushuId2.get(byLushuId2.size() - 1).getLatLng()));
                }
            }
        }
        GoogleClient.requestStaticMap(new Callback() {
            @Override
            public void onFailure(Call call, IOException iOException) {
                iOException.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) {
                try {
                    InputStream byteStream = response.body().byteStream();
                    String buildExternalDirectoryPath = AppFileUtils.buildExternalDirectoryPath(Constants.LUSHU_IMAGE);
                    if (buildExternalDirectoryPath == null) {
                        return;
                    }
                    File file = new File(buildExternalDirectoryPath);
                    if (!file.exists()) {
                        file.mkdirs();
                    }
                    AppFileUtils.createNomediaFile(file);
                    FileOutputStream fileOutputStream =
                            new FileOutputStream(buildExternalDirectoryPath + RouteBook.this.uuid + ".png");
                    byte[] bArr = new byte[1024];
                    while (true) {
                        int read = byteStream.read(bArr);
                        if (read != -1) {
                            fileOutputStream.write(bArr, 0, read);
                        } else {
                            byteStream.read(bArr);
                            fileOutputStream.write(bArr);
                            RouteBook routeBook = RouteBook.this;
                            routeBook.imageUrl =
                                    "file://" + AppFileUtils.buildExternalDirectoryPath(Constants.LUSHU_IMAGE)
                                            + RouteBook.this.uuid + ".png";
                            RouteBook.this.save();
                            App.getContext().sendBroadcast(new Intent(RouteBook.ACTION_IMAGE_LOADED));
                            return;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, this.encodingPoints, arrayList);
    }

    public String getLicenseNumberSkin() {
        return this.licenseNumberSkin;
    }

    public void setLicenseNumberSkin(String licenseNumberSkin) {
        this.licenseNumberSkin = licenseNumberSkin;
    }

    public String getLicenseNumberColor() {
        return this.licenseNumberColor;
    }

    public void setLicenseNumberColor(String licenseNumberColor) {
        this.licenseNumberColor = licenseNumberColor;
    }

    public int getStyle() {
        return this.style;
    }

    public void setStyle(int style) {
        this.style = style;
    }

    public String getThumbnail() {
        return this.thumbnail;
    }

    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
    }

    public String getSlopeThumbnail() {
        return this.slopeThumbnail;
    }

    public void setSlopeThumbnail(String slopeThumbnail) {
        this.slopeThumbnail = slopeThumbnail;
    }

    public String getEncodingPoints() {
        return this.encodingPoints;
    }

    public void setEncodingPoints(String encodingPoints) {
        this.encodingPoints = encodingPoints;
    }

    public boolean isDisplay() {
        return this.isDisplay;
    }

    public void setDisplay(boolean isDisplay) {
        this.isDisplay = isDisplay;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getServerType() {
        return this.serverType;
    }

    public void setServerType(int serverType) {
        this.serverType = serverType;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getStartAddress() {
        return this.startAddress;
    }

    public void setStartAddress(String startAddress) {
        this.startAddress = startAddress;
    }

    public String getEndAddress() {
        return this.endAddress;
    }

    public void setEndAddress(String endAddress) {
        this.endAddress = endAddress;
    }

    public double getNortheastLat() {
        return this.northeastLat;
    }

    public void setNortheastLat(double northeastLat) {
        this.northeastLat = northeastLat;
    }

    public double getNortheastLng() {
        return this.northeastLng;
    }

    public void setNortheastLng(double northeastLng) {
        this.northeastLng = northeastLng;
    }

    public double getSouthwestLat() {
        return this.southwestLat;
    }

    public void setSouthwestLat(double southwestLat) {
        this.southwestLat = southwestLat;
    }

    public double getSouthwestLng() {
        return this.southwestLng;
    }

    public void setSouthwestLng(double southwestLng) {
        this.southwestLng = southwestLng;
    }

    public long getUserId() {
        return this.userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public String getCopyrights() {
        return this.copyrights;
    }

    public void setCopyrights(String copyrights) {
        this.copyrights = copyrights;
    }

    public double getDistance() {
        return this.distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public long getImportTime() {
        return this.importTime;
    }

    public void setImportTime(long importTime) {
        this.importTime = importTime;
    }

    public boolean isImported() {
        return this.imported;
    }

    public void setImported(boolean imported) {
        this.imported = imported;
    }

    public String getFileName() {
        return this.fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getUuid() {
        return this.uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public long getServerId() {
        return this.serverId;
    }

    public void setServerId(long serverId) {
        this.serverId = serverId;
    }

    public String getUserAvatar() {
        return this.userAvatar;
    }

    public void setUserAvatar(String userAvatar) {
        this.userAvatar = userAvatar;
    }

    public int getLevel() {
        return this.level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getMedalSmall() {
        return this.medalSmall;
    }

    public void setMedalSmall(String medalSmall) {
        this.medalSmall = medalSmall;
    }

    public String getPlateNum() {
        return this.plateNum;
    }

    public void setPlateNum(String plateNum) {
        this.plateNum = plateNum;
    }

    public String getProName() {
        return this.proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public List<UserAvatarMedal> getUserAvatarMedals() {
        return this.userAvatarMedals;
    }

    public void setUserAvatarMedals(List<UserAvatarMedal> userAvatarMedals) {
        this.userAvatarMedals = userAvatarMedals;
    }

    public int getCommentCount() {
        return this.commentCount;
    }

    public void setCommentCount(int commentCount) {
        this.commentCount = commentCount;
    }

    public int getDownloadCount() {
        return this.downloadCount;
    }

    public void setDownloadCount(int downloadCount) {
        this.downloadCount = downloadCount;
    }

    public boolean isCollected() {
        return this.isCollected;
    }

    public void setIsCollected(boolean isCollected) {
        this.isCollected = isCollected;
    }

    public int getCollectCount() {
        return this.collectCount;
    }

    public void setCollectCount(int collectCount) {
        this.collectCount = collectCount;
    }

    public int getSport() {
        return this.sport;
    }

    public void setSport(int sport) {
        this.sport = sport;
    }

    public int getSourceType() {
        return this.sourceType;
    }

    public void setSourceType(int sourceType) {
        this.sourceType = sourceType;
    }

    public long getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public boolean isUpload() {
        return this.isUpload;
    }

    public void setIsUpload(boolean isUpload) {
        this.isUpload = isUpload;
    }

    public String getThreedLushu() {
        return this.threedLushu;
    }

    public void setThreedLushu(String threedLushu) {
        this.threedLushu = threedLushu;
    }

    public boolean isDownload() {
        return this.isDownload;
    }

    public void setIsDownload(boolean isDownload) {
        this.isDownload = isDownload;
    }

    public boolean isExport() {
        return this.isExport;
    }

    public void setIsExport(boolean isExport) {
        this.isExport = isExport;
    }

    public long getUpdateTime() {
        long j = this.updateTime;
        return j > 0 ? j : this.createTime / 1000;
    }

    public void setUpdateTime(long updateTime) {
        this.updateTime = updateTime;
    }

    public boolean isNeedUpdate() {
        return this.needUpdate;
    }

    public void setNeedUpdate(boolean needUpdate) {
        this.needUpdate = needUpdate;
    }

    public double getMinGrade() {
        return this.minGrade;
    }

    public void setMinGrade(double minGrade) {
        this.minGrade = minGrade;
    }

    public double getMaxGrade() {
        return this.maxGrade;
    }

    public void setMaxGrade(double maxGrade) {
        this.maxGrade = maxGrade;
    }

    public double getAvgGrade() {
        return this.avgGrade;
    }

    public void setAvgGrade(double avgGrade) {
        this.avgGrade = avgGrade;
    }

    public double getMinAltitude() {
        return this.minAltitude;
    }

    public void setMinAltitude(double minAltitude) {
        this.minAltitude = minAltitude;
    }

    public double getMaxAltitude() {
        return this.maxAltitude;
    }

    public void setMaxAltitude(double maxAltitude) {
        this.maxAltitude = maxAltitude;
    }

    public double getElevationGain() {
        return this.elevationGain;
    }

    public void setElevationGain(double elevationGain) {
        this.elevationGain = elevationGain;
    }

    public double getElevationLoss() {
        return this.elevationLoss;
    }

    public void setElevationLoss(double elevationLoss) {
        this.elevationLoss = elevationLoss;
    }

    public boolean isUploadEnable() {
        return this.uploadEnable;
    }

    public void setUploadEnable(boolean uploadEnable) {
        this.uploadEnable = uploadEnable;
    }

    public int getCaTdfLevel() {
        return this.caTdfLevel;
    }

    public void setCaTdfLevel(int caTdfLevel) {
        this.caTdfLevel = caTdfLevel;
    }

    public JSONArray getWaypointJsonArray() {
        if (this.waypointString != null) {
            try {
                return new JSONArray(this.waypointString);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public void setWaypointJsonArray(JSONArray waypointJsonArray) {
        if (waypointJsonArray != null) {
            this.waypointString = waypointJsonArray.toString();
        }
    }

    public JSONArray getNotepointJsonArray() {
        if (this.notepointString != null) {
            try {
                return new JSONArray(this.notepointString);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public void setNotepointJsonArray(JSONArray notepointJsonArray) {
        if (notepointJsonArray != null) {
            this.notepointString = notepointJsonArray.toString();
        }
    }

    public List<Notepoint> getNotepointList() {
        ArrayList<Notepoint> arrayList = new ArrayList<>();
        JSONArray notepointJsonArray = getNotepointJsonArray();
        if (notepointJsonArray != null) {
            for (int i = 0; i < notepointJsonArray.length(); i++) {
                try {
                    arrayList.add(new Notepoint((JSONObject) notepointJsonArray.get(i)));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return arrayList;
    }

    public String getAltitudeString() {
        return this.altitudeString;
    }

    public void setAltitudeString(String altitudeString) {
        this.altitudeString = altitudeString;
    }

    public JSONArray getAltitudeJsonArray() {
        if (this.altitudeString != null) {
            try {
                return new JSONArray(this.altitudeString);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public void setAltitudeJsonArray(JSONArray altitudeJsonArray) {
        if (altitudeJsonArray != null) {
            this.altitudeString = altitudeJsonArray.toString();
        }
    }

    public int getSimilarityNum() {
        return this.similarityNum;
    }

    public void setSimilarityNum(int similarityNum) {
        this.similarityNum = similarityNum;
    }

    public TrackSegment getTrackSegment() {
        return this.trackSegment;
    }

    public void setTrackSegment(TrackSegment trackSegment) {
        this.trackSegment = trackSegment;
    }

    public List<RouteBookPoint> getLushuPoints() {
        return this.lushuPoints;
    }

    public void setLushuPoints(List<RouteBookPoint> lushuPoints) {
        this.lushuPoints = lushuPoints;
    }

    public List<Waypoint> getWayPoints() {
        return this.wayPoints;
    }

    public void setWayPoints(List<Waypoint> wayPoints) {
        this.wayPoints = wayPoints;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeDouble(this.distance);
        dest.writeString(this.title);
        dest.writeLong(this.importTime);
        dest.writeByte(this.imported ? (byte) 1 : (byte) 0);
        dest.writeString(this.fileName);
        dest.writeString(this.uuid);
        dest.writeLong(this.serverId);
        dest.writeString(this.startAddress);
        dest.writeString(this.endAddress);
        dest.writeLong(this.userId);
        dest.writeString(this.imageUrl);
        dest.writeString(this.description);
        dest.writeInt(this.serverType);
        dest.writeString(this.username);
        dest.writeString(this.userAvatar);
        dest.writeInt(this.level);
        dest.writeString(this.medalSmall);
        dest.writeString(this.plateNum);
        dest.writeString(this.proName);
        dest.writeTypedList(this.userAvatarMedals);
        dest.writeInt(this.commentCount);
        dest.writeInt(this.downloadCount);
        dest.writeByte(this.isCollected ? (byte) 1 : (byte) 0);
        dest.writeInt(this.collectCount);
        dest.writeInt(this.sport);
        dest.writeInt(this.sourceType);
        dest.writeLong(this.createTime);
        dest.writeByte(this.isUpload ? (byte) 1 : (byte) 0);
        dest.writeString(this.threedLushu);
        dest.writeInt(this.similarityNum);
        dest.writeByte(this.isDownload ? (byte) 1 : (byte) 0);
        dest.writeByte(this.isExport ? (byte) 1 : (byte) 0);
        dest.writeParcelable(this.trackSegment, flags);
        dest.writeString(this.waypointString);
        dest.writeString(this.notepointString);
        dest.writeString(this.altitudeString);
        dest.writeDouble(this.northeastLat);
        dest.writeDouble(this.northeastLng);
        dest.writeDouble(this.southwestLat);
        dest.writeDouble(this.southwestLng);
        dest.writeString(this.copyrights);
        dest.writeByte(this.isDisplay ? (byte) 1 : (byte) 0);
        dest.writeString(this.encodingPoints);
        dest.writeLong(this.updateTime);
        dest.writeByte(this.needUpdate ? (byte) 1 : (byte) 0);
        dest.writeDouble(this.minGrade);
        dest.writeDouble(this.maxGrade);
        dest.writeDouble(this.avgGrade);
        dest.writeDouble(this.minAltitude);
        dest.writeDouble(this.maxAltitude);
        dest.writeDouble(this.elevationGain);
        dest.writeDouble(this.elevationLoss);
        dest.writeByte(this.uploadEnable ? (byte) 1 : (byte) 0);
        dest.writeTypedList(this.lushuPoints);
        dest.writeTypedList(this.wayPoints);
        dest.writeInt(this.caTdfLevel);
        dest.writeInt(this.style);
        dest.writeString(this.thumbnail);
        dest.writeString(this.slopeThumbnail);
        dest.writeString(this.licenseNumberColor);
        dest.writeString(this.licenseNumberSkin);
    }

    @Override
    public Long getNavId() {
        return getId();
    }

    @Override
    public Long getNavServerId() {
        return getServerId();
    }

    @NonNull
    @Override
    public String toString() {
        return "RouteBook{" + "userAvatarMedals=" + userAvatarMedals + ", altitudeString='" + altitudeString + '\'' + ", avgGrade=" + avgGrade + ", caTdfLevel=" + caTdfLevel + ", collectCount=" + collectCount + ", commentCount=" + commentCount + ", copyrights='" + copyrights + '\'' + ", createTime=" + createTime + ", description='" + description + '\'' + ", distance=" + distance + ", downloadCount=" + downloadCount + ", elevationGain=" + elevationGain + ", elevationLoss=" + elevationLoss + ", encodingPoints='" + encodingPoints + '\'' + ", endAddress='" + endAddress + '\'' + ", fileName='" + fileName + '\'' + ", imageUrl='" + imageUrl + '\'' + ", importTime=" + importTime + ", imported=" + imported + ", isCollected=" + isCollected + ", isDisplay=" + isDisplay + ", isDownload=" + isDownload + ", isExport=" + isExport + ", isUpload=" + isUpload + ", level=" + level + ", licenseNumberColor='" + licenseNumberColor + '\'' + ", licenseNumberSkin='" + licenseNumberSkin + '\'' + ", lushuPoints=" + lushuPoints + ", maxAltitude=" + maxAltitude + ", maxGrade=" + maxGrade + ", medalSmall='" + medalSmall + '\'' + ", minAltitude=" + minAltitude + ", minGrade=" + minGrade + ", needUpdate=" + needUpdate + ", northeastLat=" + northeastLat + ", northeastLng=" + northeastLng + ", notepointString='" + notepointString + '\'' + ", plateNum='" + plateNum + '\'' + ", proName='" + proName + '\'' + ", serverId=" + serverId + ", serverType=" + serverType + ", similarityNum=" + similarityNum + ", slopeThumbnail='" + slopeThumbnail + '\'' + ", sourceType=" + sourceType + ", southwestLat=" + southwestLat + ", southwestLng=" + southwestLng + ", sport=" + sport + ", startAddress='" + startAddress + '\'' + ", style=" + style + ", threedLushu='" + threedLushu + '\'' + ", thumbnail='" + thumbnail + '\'' + ", title='" + title + '\'' + ", trackSegment=" + trackSegment + ", updateTime=" + updateTime + ", uploadEnable=" + uploadEnable + ", userAvatar='" + userAvatar + '\'' + ", userId=" + userId + ", username='" + username + '\'' + ", uuid='" + uuid + '\'' + ", wayPoints=" + wayPoints + ", waypointString='" + waypointString + '\'' + '}';
    }
}
